import socket
import simplejson
import cv2
import numpy as np
cmd = {
        "opType":5,
        "setData":[],
        "waveLength":0
       }
address = ('127.0.0.1', 8090)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(address)

cmd_json = simplejson.dumps(cmd)
s.send(cmd_json)
# data=np.array()
data = ''
while(True):
    data += s.recv(304266)
    # print type(data)
    # print data
    # json = simplejson(data)
    # print 'the data received is', json
    if(len(data) < 304266):
        print("file less,",len(data))
    elif(len(data) == 304266):
        print("file ok", len(data))
        cv2.imshow("dd",np.loads(data))
        data = ''
    elif(len(data) > 304266):
        print("file more,", len(data))
        cv2.imshow("dd", np.loads(data[0:304266]))
        data = data[304266:]

    if cv2.waitKey(1) & 0xFF == ord('q'):
    # fobj.flush()
    # fobj.close()
        cv2.destroyAllWindows()
        break
s.close()
